package com.omenkk.juc.c2;

public class demo3 {
    public static void main(String[] args) {
        Thread t1=new Thread(SynchronizedLock.instance);
        Thread t2=new Thread(SynchronizedLock.instance);
        t1.start();
        t2.start();
    }
}

class SynchronizedLock implements Runnable{
    int a;

    public SynchronizedLock(int a) {
        this.a = a;
    }

    //静态实例
static SynchronizedLock instance=new SynchronizedLock(1);
    @Override
    public void run() {
        synchronized (this){
            System.out.println("我是线程" + Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
                System.out.println("数据"+this.a);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "结束");
        }
    }
}
